﻿
Partial Class WebForm_ManageMOIExport_VBookControl
    Inherits System.Web.UI.UserControl

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            'Me.BindGV()
        End If
    End Sub

    Public Sub BindGV()
        Dim dat As New clsData
        Dim sql As New MyStringBuilder

        sql.Length = 0

        sql.AppendFormat(" Select Distinct v.VolunteerName,vb1.VolunteerID, ")
        sql.AppendFormat(" Case ")
        sql.AppendFormat(" When vb2.Status = '4' then '4' ")
        sql.AppendFormat(" Else '2' ")
        sql.AppendFormat(" End AS Status, ")
        sql.AppendFormat(" C.MOIValue AS SerialGroupID,c.Text as SerialGroupText,vb1.SerialNumber as SerialNumber,right('0'+CAST((YEAR(vb1.IssueDate)-1911) AS VARCHAR)+RIGHT(CONVERT(VARCHAR(12),vb1.IssueDate,112),4),7) as IssueBookDate,'' AS Remark ")
        sql.AppendFormat(" From VBook vb1 Left Join VBook vb2 ON vb1.VolunteerID = vb2.VolunteerID And vb2.Status='4' ")
        sql.AppendFormat(" INNER JOIN Volunteer v ON vb1.VolunteerID = v.VolunteerID ")
        sql.AppendFormat(" Left Join Village vi ON v.VillageID = vi.RegionID ")
        sql.AppendFormat("LEFT JOIN CodeMapping C ON vb1.SerialGroupID=C.Value AND TableName='VBook' AND ColumnName='SerialGroupID' ")
        sql.AppendFormat("  left JOIN (select vm.VOrganizationID,vo.VOrganizationName,vm.VolunteerID,vo.DirectUOrganizationID from VOrganizationMapping vm ")
        sql.AppendFormat("inner join VOrganizationViewV2 vo on vm.VOrganizationID=vo.VOrganizationID ) oo on v.VolunteerID=oo.VolunteerID  ")
        sql.AppendFormat(" Where vb1.Status='2' ")

        'If Me.Region1ID <> "" Then
        '    sql.AppendFormat(" And vi.Parent='{0}' ", Me.Region1ID)
        'End If

        'If Me.Region2ID <> "" Then
        '    sql.AppendFormat(" And v.VillageID='{0}' ", Me.Region2ID)
        'End If
        If Me.OrganizationID <> "0" Then
            sql.AppendFormat("and oo.DirectUOrganizationID='{0}' ", Me.OrganizationID)
        End If

        If Me.VOrganizationID <> "0" Then
            sql.AppendFormat(" And oo.VOrganizationID='{0}' ", Me.VOrganizationID)
        End If

        If Me.VolunteerID <> "" Then
            sql.AppendFormat(" And v.VolunteerID='{0}' ", Me.VolunteerID)
        End If

        If Me.VolunteerName <> "" Then
            sql.AppendFormat(" And v.VolunteerName Like '%{0}%' ", Me.VolunteerName)
        End If

        VBookDT = dat.GetData(sql)

        Me.gv.DataSource = VBookDT.DefaultView
        Me.gv.DataBind()

    End Sub

    Protected Sub gv_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles gv.PageIndexChanging
        Me.gv.PageIndex = e.NewPageIndex
        Me.BindGV()
    End Sub

    'Protected Sub gv_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gv.RowDataBound
    '    If e.Row.RowType = DataControlRowType.DataRow Then

    '        If CType(e.Row.FindControl("lblIssueDate"), Label).Text <> "" Then
    '            Dim d() As String = CType(e.Row.FindControl("lblIssueDate"), Label).Text.Split(".")     'year=d(0),month=d(1),day=d(2)

    '            '日期格式 099/01/01
    '            If d(0).Length = 2 Then
    '                d(0) = "0" + d(0)
    '            End If

    '            If d(1).Length = 1 Then
    '                d(1) = "0" + d(1)
    '            End If

    '            If d(2).Length = 1 Then
    '                d(2) = "0" + d(2)
    '            End If

    '            CType(e.Row.FindControl("lblIssueDate"), Label).Text = d(0) + "/" + d(1) + "/" + d(2)
    '        End If



    '    End If
    'End Sub

#Region "Property"
    Public Property VBookDT() As Data.DataTable
        Get
            Return ViewState("VBookDT")
        End Get
        Set(ByVal value As Data.DataTable)
            ViewState("VBookDT") = value
        End Set
    End Property
    Public Property Region1ID() As String
        Get
            Return ViewState("Region1ID")
        End Get
        Set(ByVal value As String)
            ViewState("Region1ID") = value
        End Set
    End Property

    Public Property Region2ID() As String
        Get
            Return ViewState("Region2ID")
        End Get
        Set(ByVal value As String)
            ViewState("Region2ID") = value
        End Set
    End Property

    Public Property OrganizationID() As String
        Get
            Return ViewState("OrganizationID")
        End Get
        Set(ByVal value As String)
            ViewState("OrganizationID") = value
        End Set
    End Property
    Public Property VOrganizationID() As String
        Get
            Return ViewState("VOrganizationID")
        End Get
        Set(ByVal value As String)
            ViewState("VOrganizationID") = value
        End Set
    End Property

    Public Property VolunteerName() As String
        Get
            Return ViewState("VolunteerName")
        End Get
        Set(ByVal value As String)
            ViewState("VolunteerName") = value
        End Set
    End Property

    Public Property VolunteerID() As String
        Get
            Return ViewState("VolunteerID")
        End Get
        Set(ByVal value As String)
            ViewState("VolunteerID") = value
        End Set
    End Property
#End Region


End Class
